package com.wang.friend.controller;


import com.wang.common.core.controller.BaseController;
import com.wang.common.core.domain.R;
import com.wang.common.core.domain.TableDataInfo;
import com.wang.friend.domain.exam.dto.ExamQueryDTO;
import com.wang.friend.domain.exam.dto.ExamRankDTO;
import com.wang.friend.domain.exam.vo.ExamVO;
import com.wang.friend.service.IExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "竞赛功能接口")
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private IExamService examService;

    /**
     * 以游客身份获取竞赛列表(从库中)
     *      游客登录:/semiLogin
     *      获取题目列表:/list
     */
    @Operation(summary = "以游客身份从库中获取竞赛列表的信息")
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        List<ExamVO> list = examService.list(examQueryDTO); //查询出来的是当前页码的信息
        return BaseController.getTableDataInfo(list);
    }

    /**
     * 以游客身份获取竞赛列表(从缓存中)
     *      游客登录:/semiLogin
     *      从缓存中:/redis
     *      获取题目列表:/list
     */
    @Operation(summary = "以游客身份从缓存中获取指定类型的竞赛列表")
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO){
        return examService.redisList(examQueryDTO);
    }

    @Operation(summary = "获取竞赛中的第一道题目")
    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestion(Long examId){
        return R.success(examService.getFirstQuestion(examId));
    }

    @Operation(summary = "获取当前题目的前一题")
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long examId,Long questionId){
        return R.success(examService.preQuestion(examId,questionId));
    }

    @Operation(summary = "获取当前题目的后一题")
    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long examId, Long questionId) {
        return R.success(examService.nextQuestion(examId, questionId));
    }

    @Operation(summary = "获取指定竞赛的排名列表")
    @GetMapping("/rank/list")
    public TableDataInfo rankList(ExamRankDTO examRankDTO){
        return examService.rankList(examRankDTO);
    }
}
